//
//  LMSNewTittleTableViewCell.m
//  LMS
//
//  Created by dfws on 2019/3/21.
//  Copyright © 2019年 dfws. All rights reserved.
//

#import "LMSNewTittleTableViewCell.h"
#import "DemoHelp.h"
@implementation LMSNewTittleTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configUI];
    }
    return self;
}
- (void)configUI{
    self.backgroundColor = [UIColor whiteColor];

    [self addSubview:self.bgContentView];
    [self.bgContentView addSubview:self.titleLb];
    [self.bgContentView addSubview:self.perTitleLb];
    [self.bgContentView addSubview:self.infoLb];
    [self.bgContentView addSubview:self.headCollectionView];
    
}
- (void)configureHeaderViewArray:(NSArray *)array{
 
    _titleLb.text = self.course_title;
    _perTitleLb.text = self.course_description.length?self.course_description:@"哈哈哈哈";
    _infoLb.text = self.indicatorStr.length?self.indicatorStr:@"嘿嘿嘿额没数据凑数";
    _bgContentView.backgroundColor = [UIColor whiteColor];
    CGFloat titleHeight = [DemoHelp getLB:_titleLb HeightByWidth:(kUIScreenWidth - 30)]>30*2?36*2:[DemoHelp getLB:_titleLb HeightByWidth:(kUIScreenWidth - 30)];
    
    [_titleLb mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(titleHeight));
    }];
    self.headCollectionView.dataSource = [array mutableCopy];
    
    
}
- (CGFloat)realHeight{
    return 50+[self.headCollectionView realHeight]+[DemoHelp getLB:_titleLb HeightByWidth:(kUIScreenWidth - 30)]>30*2?36*2:[DemoHelp getLB:_titleLb HeightByWidth:(kUIScreenWidth - 30)] +[DemoHelp getLB:_infoLb HeightByWidth:(kUIScreenWidth - 30)];
}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGFloat gap = 15;
//    [self mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.mas_equalTo(kUIScreenWidth);
//        make.bottom.greaterThanOrEqualTo(self->_bgContentView.mas_bottom).offset(3);
//    }];
    

    [_bgContentView mas_makeConstraints:^(MASConstraintMaker *make) {
     make.left.right.top.equalTo(self);
        make.bottom.left.right.equalTo(self);
    }];
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_bgContentView).offset(gap);
        make.left.equalTo(self->_bgContentView).offset(gap);
        make.right.equalTo(self->_bgContentView).offset(-gap);
        //        make.height.lessThanOrEqualTo(@(34*2));
    }];
    
    [_perTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_titleLb.mas_bottom).offset(gap);
        make.right.equalTo(@[self->_titleLb,self->_infoLb]);
        make.left.equalTo(@[self->_titleLb,self->_infoLb]);
    }];
    
    [_infoLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_perTitleLb.mas_bottom).offset(gap);
        make.height.equalTo(@16);
        //        make.bottom.equalTo(self).offset(-gap);
    }];
    [_headCollectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_infoLb.mas_bottom);
        make.left.equalTo(self);
        make.bottom.lessThanOrEqualTo(self->_bgContentView.mas_bottom).offset(-gap);
        make.size.mas_equalTo(CGSizeMake(kUIScreenWidth, [self->_headCollectionView realHeight]));
    }];
    
}

- (UIView *)bgContentView{
    if (!_bgContentView) {
        _bgContentView = [UIView new];
    }
    return _bgContentView;
}
- (UILabel *)titleLb{
    if (!_titleLb) {
        _titleLb = [DemoHelp getLbByFont:18];
        _titleLb.numberOfLines = 2;
        _titleLb.textColor = kUIColorFromRGB(0x091522);
    }
    return _titleLb;
}

- (UILabel *)perTitleLb{
    if (!_perTitleLb) {
        _perTitleLb = [DemoHelp getLbByFont:14];
        [DemoHelp setLbHuggingAndCompress:_perTitleLb];
        _perTitleLb.numberOfLines = 0;
        _perTitleLb.textColor = kUIColorFromRGBA(0x091522, 0.95);
    }
    return _perTitleLb;
}
- (UILabel *)infoLb{
    if (!_infoLb) {
        _infoLb = [DemoHelp getLbByFont:12];
        _infoLb.textColor = kUIColorFromRGBA(0x091522, 0.7);
    }
    return _infoLb;
}
- (BsCollectionView *)headCollectionView{
    if (!_headCollectionView) {
        _headCollectionView = [[BsCollectionView alloc]initWithItemArray:@[@"高级酒店管理",@"酒店前台",@"酒店新人超级前台课程",@"酒店新手",@"酒店打工哈根数据啊工商局和按时开酒吧肯定会给"]];
    }
    return _headCollectionView;
}
@end
